/*
 * @Author: your name
 * @Date: 2020-09-15 16:00:11
 * @LastEditTime: 2020-09-18 08:17:28
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \tower_defense_demo\assets\scripts\about_scene.ts
 */

import { SoundMgr } from "./sound_mgr"
import LoadingDoor from "./loading_door"

const {ccclass, property} = cc._decorator;

@ccclass
export default class AboutScene extends cc.Component {

    @property(LoadingDoor)
    public door: LoadingDoor = null;
    
    private go_back: boolean = false;

    onLoad () {
        this.go_back = false;
    }

    // 开门
    start () {
        this.door.door_state = 0;
        this.door.open_the_door(null);
    }

    // 跳转到home场景
    public goto_home(): void {
        if (this.go_back) {     // 防止多次点击
            return;
        }

        // 播放音效
        SoundMgr.play_effect("sounds/click");

        this.go_back = true;
        this.door.close_the_door(()=>{
            cc.director.loadScene("home_scene", ()=>{
                let home_scene = cc.find("Canvas/home_scene").getComponent("home_scene");
                home_scene.close_door();
            });
        })
    }
}
